import {
  AfterViewInit,
  ComponentFactoryResolver,
  ComponentRef,
  Directive,
  ElementRef,
  Injector,
  Input,
  Renderer2,
  Type,
  ViewContainerRef
} from '@angular/core';

@Directive({
  selector: '[appModuleLoader]'
})
export class ModuleLoaderDirective implements AfterViewInit {

  @Input() appModuleLoader: Type<any>;

  private componentRef: ComponentRef<any>;

  constructor(private _viewContainerRef: ViewContainerRef,
              private _renderer2: Renderer2,
              private _elementRef: ElementRef,
              private _injector: Injector,
              private _componentFactoryResolver: ComponentFactoryResolver) {
  }

  ngAfterViewInit() {
    const componentFactory = this._componentFactoryResolver.resolveComponentFactory(this.appModuleLoader);
    // this.componentRef = componentFactory.create(this._injector);
    this._viewContainerRef.createComponent(componentFactory);
  }

}
